package JavaFiler;

import java.util.ArrayList;
/**
 *
 * @author Gjerde & Hoff
 */
public class Task implements Constants {

    private int difficulty, taskId, answer, unknown, haveAlt;
    private String text, hint, img_name, taskType;
    private ArrayList<TaskNumber> numbers = new ArrayList<TaskNumber>();
    private ArrayList<TaskAlt> alt = new ArrayList<TaskAlt>();
    private boolean isUnknown, doHaveAlt;

    public Task(int taskId, String type, int diffc, String txt, int ans, String img, int unknown, int haveAlt) {
        this.taskId = taskId;
        taskType = type;
        difficulty = diffc;
        text = txt;
        answer = ans;
        img_name = img;
        this.unknown = unknown;
        this.haveAlt = haveAlt;
        setIsAltStart();
        setIsUnknownStart();
    }

    public Task() {
    }
    
    //When the tasks are drawn on the webpage this method is used to determine whether alternative images should be drawn.
    public void setIsAltStart() {
        if (haveAlt != 0) {
            doHaveAlt = true;
        } else {
            doHaveAlt = false;
        }
    }
    //Used when editing tasks to toggle an unknown variable on or off.
    public void setIsUnknownStart() {
        if (unknown != 0) {
            isUnknown = true;
        } else {
            isUnknown = false;
        }
    }
    //Checks if the task has alternatives
    public boolean isDoHaveAlt() {
        return doHaveAlt;
    }
    
    //Sets that a task has alternatives
    public void setDoHaveAlt(boolean doHaveAlt) {
        this.doHaveAlt = doHaveAlt;
    }

    public int getHaveAlt() {
        return haveAlt;
    }

    public void setHaveAlt(int haveAlt) {
        this.haveAlt = haveAlt;
    }

    public void setIsUnknown(boolean isUnknown) {
        this.isUnknown = isUnknown;
    }

    public boolean getIsUnknown() {
        return isUnknown;
    }

    public int getDifficulty() {
        return difficulty;
    }

    public void setDifficulty(int difficulty) {
        this.difficulty = difficulty;
    }

    public String getHint() {
        return hint;
    }

    public void setHint(String hint) {
        this.hint = hint;
    }

    public int getAnswer() {
        return answer;
    }

    public void setAnswer(int ans) {
        this.answer = ans;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }

    public void clearNumbers() {
        this.numbers.clear();
    }

    public void setNumbers(TaskNumber thenumbers) {
        this.numbers.add(thenumbers);
    }

    /* Adds a new alternative to the task */
    public void addNewAlt(String altern, int id) {
        int altId = alt.get(id).getAltId();
        alt.get(id).setTaskId(taskId);
        alt.get(id).setAlternative(altern);
        alt.get(id).setTaskId(altId);
    }

    public ArrayList<TaskNumber> getNumbers() {
        return numbers;
    }

    public ArrayList<TaskAlt> getAlt() {
        return alt;
    }

    public void setAlt(TaskAlt alt) {
        this.alt.add(alt);
    }

    public String getImg_name() {
        return img_name;
    }

    public void setImg_name(String img_name) {
        this.img_name = img_name;
    }

    public int getUnknown() {
        return unknown;
    }

    public void setUnknown(int unknown) {
        this.unknown = unknown;
    }
}
